package com.xc.h05.controller.weichen;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.HeartMarkQ;
import com.xc.h05.service.weichen.HeartMarkQService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/heartmarkq")
public class HeartMarkQController {
    @Autowired
    private HeartMarkQService heartMarkQService;
    @PostMapping("/add")
    public R add(@RequestBody HeartMarkQ heartMarkQ){
        int add = heartMarkQService.add(heartMarkQ);
        if (add>0){
            return R.ok(heartMarkQ);
        }else {
            return R.error();
        }
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") int id){
        int delete = heartMarkQService.delete(id);
        if (delete>0){
            return R.ok(delete);
        }else {
            return R.error();
        }
    }
    @PostMapping("/deletes")
    public R deletes(@RequestBody List<Integer> list){
        int deletes = heartMarkQService.deletes(list);
        if (deletes>0){
            return R.ok(deletes);
        }else {
            return R.error();
        }
    }

    @PutMapping("/update")
    public R update(@RequestBody HeartMarkQ heartMarkQ){
        int update = heartMarkQService.update(heartMarkQ);
        if (update>0){
            return R.ok(update);
        }else {
            return R.error();
        }
    }

    @GetMapping("/findByPage")
    public R findByPage(int pageNum,int pageSize,HeartMarkQ heartMarkQ){
        PageInfo<HeartMarkQ> pageInfo = heartMarkQService.findByPage(pageNum, pageSize, heartMarkQ);
        return R.ok(pageInfo);
    }
    @GetMapping("/findByTestId/{testId}")
    public R findByTestId(@PathVariable("testId") int testId){
        List<HeartMarkQ> list = heartMarkQService.findByTestId(testId);
        return R.ok(list);
    }
}
